﻿using gt.framework.Cache;
using gt.webapi.core.Entity.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace gt.webapi.core.Repositories.Impl
{
    public class MemoryIpLimitRepository : IIpLimitRepository
    {
        public void AddWhiteIps(List<string> ips)
        {
            if (ips == null || ips.Count == 0) throw new ArgumentNullException("ips");
             CacheManager.Insert<List<string>>(Constants.KEY_WHITEIP, ips);
        }

        public bool CheckIp(string ip)
        {
            var ips= CacheManager.Get<List<string>>(Constants.KEY_WHITEIP);
            if (ips == null || ips.Count == 0) return true;
            return ips.Exists(x => string.Equals(x, ip, StringComparison.CurrentCultureIgnoreCase));
        }
    }
}
